package cn_dk;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sound.midi.Soundbank;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Map;
import java.util.Set;

/**
 * @Auther:dingkai
 * @date:2021/11/30 0030 上午 10:25
 * @Desc:
 */
@WebServlet(urlPatterns = "/AServlet")
public class AServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置请求编码，避免出现请求乱码问题
        request.setCharacterEncoding("utf-8");
        //指定获取输入框内容，如果获取不到返回null
        String username = request.getParameter("username");
        String email = request.getParameter("e-mail");
        System.out.println(username);
        System.out.println(email);
        System.out.println("----------------------");
        // 获取复选框内容
        String[] hobbies = request.getParameterValues("hobby");
        if(hobbies !=null){
            for(String str: hobbies){
                System.out.println(str);
            }
        }
        System.out.println("-----------------------");
        // 获取全部内容
        Map<String, String[]> map = request.getParameterMap();
        Set<String> set = map.keySet();
        for (String key:set){
            String[] values = map.get(key);
            for (String value: values){
                System.out.println(value);
            }

        }



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
